
#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <BIcon>
#include <BReadWrite>
#include <BTexture>
#include <BImage>
#include <BLabel>
#include <BStyle>
#include <BGridLayout>
#include <BHBoxLayout>
#include <BVBoxLayout>
#include <BButton>
#include <BComboBox>
#include <BSpinBox>
#include <BListWidget>
#include <BScrollWidget>
#include <BTableWidget>
#include <BFileDialog>
#include <BMenu>
#include <BSlider>
#include <BCheckBox>
#include <BMainWindow>
#include <BButtonGroup>
#include <BStatusBar>
#include <BStackLayout>

#include "ReplaceDialog.h"
#include "CreateLayerDialog.h"
#include "WidgetPanel.h"
#include "ImageLayerPanel.h"
#include "LabelLayerPanel.h"
#include "LayerTableBoard.h"
#include "CanvasWidget.h"
#include "PixmapArea.h"

class MainWindow : public BMainWindow
{
public:
	MainWindow();
	~MainWindow();

	bool openImage(const BString& fileName);

	bool loadProject(const BString& fileName);
	bool saveProject(const BString& fileName);

protected:
	BString findValidName(const BString& base);
	void freshMenus();
	void insertLayer(BWidget* widget);

protected:
	void slotCopyShortcutTriggered();
	void slotPasteShortcutTriggered();

	void slotOpenButtonClicked(BObject* object, const BValue& value);
	void slotSaveButtonClicked(BObject* object, const BValue& value);
	void slotResetButtonClicked(BObject* object, const BValue& value);
	void slotInsertMenuTriggered(BObject* object, const BValue& value);

	void slotModifyMenuTrigger(BObject* object, const BValue& value);
	void slotZoomValueChanged(BObject* object, const BValue& value);
	void slotZoomInArrowClicked(BObject* object, const BValue& value);
	void slotZoomOutArrowClicked(BObject* object, const BValue& value);
	void slotZoomEditFinished(BObject* object, const BValue& value);
	void slotResetZoomButtonClicked();
	void slotButtonGroupChecked(BObject* object, const BValue& value);
	void slotApplyOperation(BObject* object, const BValue& value);
	void slotRemoveOperation(BObject* object, const BValue& value);
	void slotSelection(BObject* object, const BValue& value);

	void slotArrowUpClicked();
	void slotArrowDownClicked();
	void slotLayerInsertClicked();
	void slotLayerRemoveClicked();
	void slotCutoffButtonClicked();
	void slotLayerExportClicked();
	void slotImageSizeChanged(BObject* object, const BValue& value);
	void slotLayerItemSelected(BObject* object, const BValue& value);

	void slotEyeButtonChecked(BObject* object, const BValue& value);
	void slotReplaceDialogClosed(BObject* object, const BValue& value);

	void slotPixmapAreaLayerRemoved(BObject* object, const BValue& value);
	void slotPixmapAreaZoomChanged(BObject* object, const BValue& value);
	void slotPixmapAreaSelectionChanged(BObject* object, const BValue& value);
	void slotPixmapAreaOperationEscape(BObject* object, const BValue& value);
	void slotPixmapAreaRightClicked(BObject* object, const BValue& value);
	void slotPixmapAreaDoubleClicked(BObject* object, const BValue& value);
	void slotPixmapAreaDragDropped(BObject* object, const BValue& value);

	void slotTurnHorActionTriggered(BObject* object, const BValue& value);
	void slotTurnVerActionTriggered(BObject* object, const BValue& value);
	void slotRollLeftActionTriggered(BObject* object, const BValue& value);
	void slotRollRightActionTriggered(BObject* object, const BValue& value);
	void slotAlignButtonClicked(BObject* object, const BValue& value);

	void slotWidgetOrderAdjusted(BObject* object, const BValue& value);
	void slotInsertImageLayer(BObject* object, const BValue& value);
	void slotRemoveImageLayer(BObject* object, const BValue& value);
	void slotImageLayerRenamed(BObject* object, const BValue& value);
	void slotImageLayerFramed(BWidget* widget, const BValue& value);
	void slotLayerPoint(BObject* object, const BValue& value);
	void slotAreaPoint(BObject* object, const BValue& value);

protected:
	virtual void styleEvent(const BEvent& event);
	virtual void updateEvent(const BEvent& event);

private:
	BButton*				_openButton;
	BButton*				_saveButton;
	BButton*				_resetButton;
	BButton*				_insertButton;
	BButton*				_canvasButton;
	BButton*				_modifyButton;

	BSlider*				_zoomSlider;
	BButton*				_zoomInArrow;
	BButton*				_zoomOutArrow;
	BSpinBox*				_zoomSpinBox;
	BButton*				_resetZoomButton;

	BStatusBar*				_statusBar;
	BSpinBox*				_layerXSpinBox;
	BSpinBox*				_layerYSpinBox;
	BSpinBox*				_globalXSpinBox;
	BSpinBox*				_globalYSpinBox;

	BMenu*					_insertMenu;
	BHolder<BMenu>			_pixmapMenu;
	BMenu*					_canvasMenu;
	CanvasWidget*			_canvasWidget;
	BDialog*				_canvasDialog;
	BMenu*					_modifyMenu;

	BHolder<BButtonGroup>		_buttonGroup;
	PixmapArea*					_pixmapArea;
	BSpacer*					_pixmapSpacer;
	BVBoxLayout*				_rightLayout;
	BScrollWidget*				_propertyWidget;
	BHolder<ReplaceDialog>		_replaceDialog;
	BHolder<CreateLayerDialog>	_createLayerDialog;
	BHolder<BEventFilter>		_mainEventFilter;

	BButton*				_arrowUpButton;
	BButton*				_arrowDownButton;
	BButton*				_layerInsertButton;
	BButton*				_layerExportButton;
	BButton*				_layerRemoveButton;
	BButton*				_layerCutoffButton;
	BComboBox*				_imageSizeComboBox;
	LayerTableBoard*		_layerTableBoard;
};

#endif